package com.xliu.cs.openproject.lianliankan.view;

import com.xliu.cs.openproject.lianliankan.Coordinate;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * A Panel showing a picture
 */
public class PicturePanel extends JPanel {
    /** the image panel draws */
    private BufferedImage image;
    /** row index */
    private final int rowIdx;
    /** column index */
    private final int colIdx;

    public PicturePanel(BufferedImage img, int width, int height, int rowIdx, int colIdx) {
        image = img;
        this.rowIdx = rowIdx;
        this.colIdx = colIdx;
        setPreferredSize(new Dimension(width, height));
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
    }

    public Coordinate getCoordinate() {
        return new Coordinate(rowIdx, colIdx);
    }

}

